<html>
<head><meta charset="utf-8"><title>Representation of defaulted, associated methods · rustdoc · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/index.html">rustdoc</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Representation.20of.20defaulted.2C.20associated.20methods.html">Representation of defaulted, associated methods</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="223785316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Representation%20of%20defaulted%2C%20associated%20methods/near/223785316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Representation.20of.20defaulted.2C.20associated.20methods.html#223785316">(Jan 23 2021 at 23:56)</a>:</h4>
<p>How would one differentiate trait methods that are defaulted from those that must be provided? It seems that both kinds of Method items have <code>has_body: true</code>. Is this a bug?</p>



<a name="223786341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Representation%20of%20defaulted%2C%20associated%20methods/near/223786341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Representation.20of.20defaulted.2C.20associated.20methods.html#223786341">(Jan 24 2021 at 00:22)</a>:</h4>
<p>According to a quick glance at the RFC, <code>has_body</code> should be false in a trait definition with, well, no body. So it sounds like a bug. I'll take a look, and see if I can write up a fix + add some tests</p>



<a name="223786650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Representation%20of%20defaulted%2C%20associated%20methods/near/223786650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Representation.20of.20defaulted.2C.20associated.20methods.html#223786650">(Jan 24 2021 at 00:31)</a>:</h4>
<p>Reproduction case:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">ThisIsATrait</span>: <span class="nb">Clone</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="sd">/// An ordinary method taking `&amp;self`.</span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">method</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">param</span>: <span class="kt">usize</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<div class="codehilite" data-code-language="Text only"><pre><span></span><code>Warning: Unhandled trait item: Item { id: Id("0:25"), crate_id: 0, name: Some("method"), source: Some(Span { filename: "src/lib.rs", begin: (41, 4), end: (41, 35) }), visibility: Public, docs: "An ordinary method taking `&amp;self`.", links: {}, attrs: [], deprecation: None, kind: Method, inner: MethodItem(Method { decl: FnDecl { inputs: [("self", BorrowedRef { lifetime: None, mutable: false, type_: Generic("Self") }), ("param", Primitive("usize"))], output: None, c_variadic: false }, generics: Generics { params: [], where_predicates: [] }, header: "", has_body: true }) }
</code></pre></div>



<a name="223786779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Representation%20of%20defaulted%2C%20associated%20methods/near/223786779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> HeroicKatora <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Representation.20of.20defaulted.2C.20associated.20methods.html#223786779">(Jan 24 2021 at 00:34)</a>:</h4>
<p>Another interesting case: <code>Method</code> does not have an ABI but it is valid to add an ABI annotation to trait methods.</p>



<a name="223787562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Representation%20of%20defaulted%2C%20associated%20methods/near/223787562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Representation.20of.20defaulted.2C.20associated.20methods.html#223787562">(Jan 24 2021 at 00:54)</a>:</h4>
<p><code>has_body: true</code> - nice</p>



<a name="223787663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Representation%20of%20defaulted%2C%20associated%20methods/near/223787663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Representation.20of.20defaulted.2C.20associated.20methods.html#223787663">(Jan 24 2021 at 00:57)</a>:</h4>
<p>Okay, so a <code>clean::Function</code> doesn't provide that item, and the way <code>From</code> was implemented is throwing out the extra data. I think I know how to fix it :P</p>



<a name="223789556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Representation%20of%20defaulted%2C%20associated%20methods/near/223789556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CraftSpider <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Representation.20of.20defaulted.2C.20associated.20methods.html#223789556">(Jan 24 2021 at 01:48)</a>:</h4>
<p>PR up to fix it: <a href="https://github.com/rust-lang/rust/pull/81318">https://github.com/rust-lang/rust/pull/81318</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>